{% extends "shared/layout.volt" %}
{% block content %}
    <h1 class="page-header">
        资源列表
        {% if Member.isPermission('Member','edit') %}
            <a href="{{ url("resource/edit") }}" class="btn btn-default btn-sm pull-right"><i class="fa fa-plus"></i> 新增数据</a>
        {% endif %}
    </h1>
    <div class="table-responsive">
        <table class="table-tidy">
            <thead class="table-tidy-head">
            <tr>
                <th style="width: 80px;">#</th>
                <th>资源名称</th>
                <th style="width: 180px;">控制器</th>
                <th style="width: 210px;">方法</th>
                <th style="width: 120px;">导航显示</th>
                <th style="width: 180px;">排序</th>
                <th style="width: 120px;">小图标</th>
                <th style="width: 80px;">操作</th>
            </tr>
            </thead>
            <tbody class="table-tidy-body">
            {% for item in List %}
                {% if item['item'] is empty %}
                    <?php
                        $resource = new \Cohuna\Models\CohunaPermissionResource();
                        $resource->resource_name = '其他';
                        $resource->resource_id = 0;
                        $item['item'] = $resource;
                    ?>
                {% endif %}
                <tr>
                    <td>{{ item['item'].resource_id }}</td>
                    <td>
                        <?php if(count($item['actions']) > 1 || $item['item']->resource_id == 0):?>
                            <div class="simple-tree" data-id="{{ item['item'].resource_id }}">
                                <i class="fa fa-plus" aria-hidden="true"></i>
                            </div>
                        <?php else:?>
                        <div class="simple-tree" data-id="{{ item['item'].resource_id }}"></div>
                        <?php endif ?>
                        {{ item['item'].resource_name }}
                    </td>
                    <td>{{ item['item'].controller_name }}</td>
                    <td>{{ item['item'].action_name }}</td>
                    <td>{{ item['item'].is_show_menu == 1?'是':'否' }}</td>
                    <td>{{ item['item'].sort_index }}</td>
                    <td>
                        {% if item['item'].icon_class is not empty %}
                        <i class="{{ item['item'].icon_class }}"></i>
                        {% else %}
                            无
                        {% endif %}
                    </td>
                    <td>
                        <a href="{{ url('resource/edit') }}?resource_id={{ item['item'].resource_id }}">编辑</a>
                    </td>
                </tr>
                {% for subItem in item['actions'] %}
                    {% if subItem.resource_id != item['item'].resource_id %}
                    <tr data-parent-id="{{ item['item'].resource_id }}" style="display: none">
                        <td>{{ subItem.resource_id }}</td>
                        <td>
                            <div class="simple-tree-none"></div>
                            {{ subItem.resource_name }}
                        </td>
                        <td>{{ subItem.controller_name }}</td>
                        <td>{{ subItem.action_name }}</td>
                        <td>{{ subItem.is_show_menu == 1?'是':'否' }}</td>
                        <td>{{ subItem.sort_index }}</td>
                        <td>
                            {% if subItem.icon_class is not empty %}
                                <i class="{{ subItem.icon_class }}"></i>
                            {% else %}
                                无
                            {% endif %}
                        </td>
                        <td>
                            <a href="{{ url('resource/edit') }}?resource_id={{ subItem.resource_id }}">编辑</a>
                        </td>
                    </tr>
                    {% endif %}
                {% endfor %}
            {% else %}
                <tr>
                    <td class="text-center" colspan="8">暂无数据</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
{% block footer %}
<script type="text/javascript">
    $(function () {
       $(".simple-tree").on('click',function () {
           var state = $(this).hasClass('simple-tree-open');
          var pid = $(this).attr('data-id');
          if(state) {
              $(this).removeClass('simple-tree-open').addClass('simple-tree-close').parents('tr').siblings('[data-parent-id="' + pid + '"]').hide();
          }else{
              $(this).removeClass('simple-tree-close').addClass('simple-tree-open').parents('tr').siblings('[data-parent-id="' + pid + '"]').show();
          }
       });
    });
</script>
{% endblock %}